package com.scc.generate.word.generator;

import javax.sql.DataSource;

import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;

import cn.smallbun.screw.core.Configuration;
import cn.smallbun.screw.core.engine.EngineConfig;
import cn.smallbun.screw.core.engine.EngineTemplateType;
import cn.smallbun.screw.core.execute.DocumentationExecute;
import cn.smallbun.screw.core.process.ProcessConfig;

/**
 * @ClassName: GenerateMysqlWord
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @author javascc@126.com
 * @date 2023年3月27日 下午3:49:19
 * 
 */
public class DocGenerator {
	public void generate(DocConfig config) throws Exception {
		HikariConfig hikariConfig = new HikariConfig();
		hikariConfig.setDriverClassName(config.getDriverClassName());
		hikariConfig.setJdbcUrl(config.getUrl());
		hikariConfig.setUsername(config.getUname());
		hikariConfig.setPassword(config.getPwd());
		hikariConfig.addDataSourceProperty("useInformationSchema", "true");
		hikariConfig.setMinimumIdle(2);
		hikariConfig.setMaximumPoolSize(5);
		DataSource dataSource = new HikariDataSource(hikariConfig);
		EngineConfig engineConfig = EngineConfig.builder().fileName(config.getTitle() + "-" + config.getVersion())
				.fileOutputDir(config.getFilePath()).openOutputDir(config.isOpenOutputDir()).fileType(config.getType())
				.produceType(EngineTemplateType.freemarker).build();
		ProcessConfig processConfig = ProcessConfig.builder().ignoreTableName(config.getIgnoreTableName())
				.ignoreTablePrefix(config.getIgnorePrefix()).ignoreTableSuffix(config.getIgnoreSuffix()).build();
		Configuration configuration = Configuration.builder().organization("personal")
				.organizationUrl("https://my.oschina.net/shyloveliyi").version(config.getVersion())
				.title(config.getTitle()).description("数据库设计文档生成-scc").dataSource(dataSource).engineConfig(engineConfig)
				.produceConfig(processConfig).build();
		new DocumentationExecute(configuration).execute();
	}
}
